{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1.【选择】以下说法正确的是：（ ）    \n",
    "\n",
    "A.try、except、finally三者必须同时使用，缺一不可。  \n",
    "B.finally的作用与else相同。   \n",
    "C.assert主要用于“设置检查点”，当检查条件为真时，则抛出AssertionError。  \n",
    "D.assert语句的断言内容是可以空缺的。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "答案：D。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2.【选择】SyntaxError表示（ ）。  \n",
    "\n",
    "A.可疑的语法警告。   \n",
    "B.传入无效的参数。  \n",
    "C.语法错误。  \n",
    "D.缩进错误。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "答案：C。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3.【填空】魔术命令（ ）可以控制异常信息显示的详细程度，其参数选项从简到繁分别是：（ ）、（ ）、（ ）。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "答案：%xmode；Plain；Context；Verbose。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "4.【填空】请写出以下程序的运行结果：（ ） \n",
    "```\n",
    ">>> def run():   \n",
    "...     try:    \n",
    "...         import math   \n",
    "...         x=-5   \n",
    "...         assert x>=0,'参数x取值范围有误'   \n",
    "...     except Exception as ex:   \n",
    "...         print('异常类型： ',ex.__class__.__name__)   \n",
    "...         print('异常信息： ',ex)   \n",
    ">>> run()```"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "答案：  \n",
    "异常类型：  AssertionError  \n",
    "异常信息：  参数x取值范围有误"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "5.【填空】请根据程序输出结果，在程序空白位置补充正确的代码。\n",
    "```\n",
    "x=[1,2,3]\n",
    "try:\n",
    "    print(x[3])\n",
    "except __________:   \n",
    "    print(error)\n",
    "__________    \n",
    "    print('程序运行结束')\n",
    "```\n",
    "\n",
    "程序运行后的输出结果如下：     \n",
    "list index out of range   \n",
    "程序运行结束\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "答案：IndexError as error；finally:  \n",
    "解析：（1）该程序是用来捕捉处理下标超出范围时引发的异常。（2）“finally:”请勿漏掉冒号。"
   ]
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python [default]",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
